package com.sunnos.express.service;

import java.util.List;
import java.util.Map;

import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;
import org.springframework.transaction.annotation.Transactional;

import com.sunnos.express.entity.Customer;
import com.sunnos.express.mapper.CustomerMapper;

@Service
public class CustomerService {
	@Autowired
	private CustomerMapper customerMapper;

	public Customer getCustomer(Map<String,Object> param) {
		return customerMapper.getCustomer(param);
	}

	public List<Customer> getCustomerList(Map<String,Object> param) {
		return customerMapper.getCustomerList(param);
	}

	public int getCustomerListTotal(Map<String,Object> param) {
		return customerMapper.getCustomerListTotal(param);
	}

	@Transactional
	public void insertCustomer(Customer customer) {
		customerMapper.insertCustomer(customer);
	}

	@Transactional
	public void updateCustomer(Customer customer) {
		customerMapper.updateCustomer(customer);
	}

	@Transactional
	public void deleteCustomer(Map<String,Object> param) {
		String ids = (String)param.get("ids");
		String[] idsArray = ids.split(",");
		for(int i=0;i<idsArray.length;i++) {
			customerMapper.deleteCustomer(Integer.parseInt(idsArray[i]));
		}
	}
}
